
<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <meta charset="utf-8"></meta>
      <meta name="viewport" content="width=device-width, initial-scale=1.0"></meta>
      <title>10.11.&nbsp;Date and Time Conversions - Chapter&nbsp;10.&nbsp;Utility Functions</title>
      <link rel="stylesheet" type="text/css" href="../../docbook.css"></link>
      <link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans:400,300,400italic,600,300italic"></link>
      <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/codemirror.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/theme/neo.min.css"></link>
      <link rel="stylesheet" type="text/css" href="../../css/chunked-base.css"></link>
      <link rel="stylesheet" type="text/css" href="../../css/extra.css"></link><script src="//code.jquery.com/jquery-1.12.4.js" type="text/javascript"></script><script src="//cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js" type="text/javascript"></script><script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" type="text/javascript"></script><script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/codemirror.min.js" type="text/javascript"></script><script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/addon/runmode/runmode.min.js" type="text/javascript"></script><script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/mode/cypher/cypher.min.js" type="text/javascript"></script><script src="../../javascript/datatable.js" type="text/javascript"></script><script src="../../javascript/colorize.js" type="text/javascript"></script><script src="../../javascript/tabs-for-chunked.js" type="text/javascript"></script><script src="../../javascript/mp-nav.js" type="text/javascript"></script><script src="../../javascript/versionswitcher.js" type="text/javascript"></script><script src="../../javascript/version.js" type="text/javascript"></script><script src="//s3-eu-west-1.amazonaws.com/alpha.neohq.net/docs/new-manual/assets/search.js" type="text/javascript"></script><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"></meta>
      <link rel="prev" href="../exact-math-functions/" title="10.14.&nbsp;Exact Math"></link>
      <link rel="next" href="../temporal-conversions/" title="10.12.&nbsp;Temporal Functions"></link>
      <link rel="shortcut icon" href="https://neo4j.com/wp-content/themes/neo4jweb/favicon.ico"></link><script>
        $(document).ready(function() {
          CodeMirror.colorize();
          tabTheSource($('body'));
          var $header = $('header').first();
          $header.prepend(
            $('<a href="" id="logo"><img src="https://neo4j.com/wp-content/themes/neo4jweb/assets/images/neo4j-logo-2015.png" alt="Neo4j Logo"></img></a>')
          );
          var $sidebar = $('<div id="sidebar-wrapper"></div>');
          $.get('toc.html', function (d){
            $(d).appendTo($sidebar);
            highlightToc();
            highlightLibraryHeader();
          });
          $sidebar.insertAfter($('header').first());
        });
        </script></head>
   <body>
      <header>
         <div class="searchbox">
            <form id="search-form" class="search" name="search-form" role="search"><input id="search-form-input" name="q" title="search" type="search" lang="en" placeholder="Search Neo4j docs..." aria-label="Search Neo4j documentation" max-length="128" required="required"></input><input id="search-form-button" type="submit" value="Search"></input></form>
         </div>
         <ul class="documentation-library">
            <li><a href="https://neo4j.com/docs/operations-manual/current">Operations Manual</a></li>
            <li><a href="https://neo4j.com/docs/developer-manual/current/">Developer Manual</a></li>
            <li><a href="https://neo4j.com/docs/ogm-manual/current/">OGM Manual</a></li>
            <li><a href="https://neo4j.com/docs/graph-algorithms/current/">Graph Algorithms</a></li>
            <li><a href="https://neo4j-contrib.github.io/neo4j-apoc-procedures/3.4/">APOC</a></li>
            <li><a href="https://neo4j.com/docs/java-reference/current/">Java Reference</a></li>
         </ul>
         <nav id="header-nav"><span class="nav-previous"><a accesskey="p" href="../exact-math-functions/"><span class="fa fa-long-arrow-left" aria-hidden="true"></span>Exact Math</a></span><span class="nav-current">
               <p class="nav-title hidden">10.11.&nbsp;Date and Time Conversions</p></span><span class="nav-next"><a accesskey="n" href="../temporal-conversions/">Temporal Functions<span class="fa fa-long-arrow-right" aria-hidden="true"></span></a></span></nav>
      </header>
      <div id="search-results" class="hidden"></div>
      <section class="section" id="datetime-conversions">
         <div class="titlepage">
            <div>
               <div>
                  <h2 class="title" style="clear: both"><a class="anchor" href="#datetime-conversions"></a>10.11.&nbsp;Date and Time Conversions
                  </h2>
               </div>
            </div>
         </div>
         <section class="section" id="_conversion_between_formatted_dates_and_timestamps">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_conversion_between_formatted_dates_and_timestamps"></a>10.11.1.&nbsp;Conversion between formatted dates and timestamps
                     </h3>
                  </div>
               </div>
            </div>
            <div class="informaltable">
               <div class="table" id="d0e12686">
                  <table class="informaltable" border="1">
                     <colgroup>
                        <col class="col_1"></col>
                        <col class="col_2"></col>
                     </colgroup>
                     <tbody>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.date.parse('2015/03/25 03:15:59',['ms'/'s'], ['yyyy/MM/dd HH:mm:ss'])</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>same as previous, but accepts custom datetime format</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.date.format(12345, ['ms'/'s'], ['yyyy/MM/dd HH:mm:ss'])</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>the same as previous, but accepts custom datetime format</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.date.systemTimezone()</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>return the system timezone display format string</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.date.currentTimestamp()</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>provides current time millis with changing values over a transaction</p>
                           </td>
                        </tr>
                     </tbody>
                  </table>
               </div>
            </div>
            <div class="itemizedlist">
               <ul class="itemizedlist" style="list-style-type: disc; ">
                  <li class="listitem">possible unit values: <code class="literal">ms,s,m,h,d</code> and their long forms <code class="literal">millis,milliseconds,seconds,minutes,hours,days</code>.
                  </li>
                  <li class="listitem">possible time zone values: Either an abbreviation such as <code class="literal">PST</code>, a full name such as <code class="literal">America/Los_Angeles</code>, or a custom ID such as <code class="literal">GMT-8:00</code>. Full names are recommended. You can view a list of full names in <a class="link" href="https://en.wikipedia.org/wiki/List_of_tz_database_time_zones" target="_top">this Wikipedia page</a>.
                  </li>
               </ul>
            </div>
         </section>
         <section class="section" id="_current_timestamp">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_current_timestamp"></a>10.11.2.&nbsp;Current timestamp
                     </h3>
                  </div>
               </div>
            </div>
            <p><code class="literal">apoc.date.currentTimestamp()</code> provides the System.currentTimeMillis which is current throughout transaction execution compared to Cypher&#8217;s timestamp()
               function which does not update within a transaction
            </p>
         </section>
         <section class="section" id="_conversion_of_timestamps_between_different_time_units">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_conversion_of_timestamps_between_different_time_units"></a>10.11.3.&nbsp;Conversion of timestamps between different time units
                     </h3>
                  </div>
               </div>
            </div>
            <div class="itemizedlist">
               <ul class="itemizedlist" style="list-style-type: disc; ">
                  <li class="listitem"><code class="literal">apoc.date.convert(12345, 'ms', 'd')</code> convert a timestamp in one time unit into one of a different time unit
                  </li>
                  <li class="listitem">possible unit values: <code class="literal">ms,s,m,h,d</code> and their long forms.
                  </li>
               </ul>
            </div>
         </section>
         <section class="section" id="_adding_subtracting_time_unit_values_to_timestamps">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_adding_subtracting_time_unit_values_to_timestamps"></a>10.11.4.&nbsp;Adding/subtracting time unit values to timestamps
                     </h3>
                  </div>
               </div>
            </div>
            <div class="itemizedlist">
               <ul class="itemizedlist" style="list-style-type: disc; ">
                  <li class="listitem"><code class="literal">apoc.date.add(12345, 'ms', -365, 'd')</code> given a timestamp in one time unit, adds a value of the specified time unit
                  </li>
                  <li class="listitem">possible unit values: <code class="literal">ms,s,m,h,d</code> and their long forms.
                  </li>
               </ul>
            </div>
         </section>
         <section class="section" id="_reading_separate_datetime_fields">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_reading_separate_datetime_fields"></a>10.11.5.&nbsp;Reading separate datetime fields:
                     </h3>
                  </div>
               </div>
            </div>
            <p>Splits date (optionally, using given custom format) into fields returning a map from field name to its value.</p><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.date.fields('2015-03-25 03:15:59')</code></pre><section class="section" id="_reading_single_datetime_field_from_utc_epoch">
               <div class="titlepage">
                  <div>
                     <div>
                        <h4 class="title"><a class="anchor" href="#_reading_single_datetime_field_from_utc_epoch"></a>10.11.5.1.&nbsp;Reading single datetime field from UTC epoch
                        </h4>
                     </div>
                  </div>
               </div>
               <p>Extracts the value of one field from a datetime epoch.</p>
               <div class="itemizedlist">
                  <ul class="itemizedlist" style="list-style-type: disc; ">
                     <li class="listitem"><code class="literal">apoc.date.field(12345)</code></li>
                  </ul>
               </div>
               <p>Following fields are supported:</p>
               <div class="informaltable">
                  <div class="table" id="d0e12804">
                     <table class="informaltable" border="1">
                        <colgroup>
                           <col class="col_1"></col>
                           <col class="col_2"></col>
                        </colgroup>
                        <thead>
                           <tr>
                              <th style="text-align: left; vertical-align: top; ">Result field</th>
                              <th style="text-align: left; vertical-align: top; ">Represents</th>
                           </tr>
                        </thead>
                        <tbody>
                           <tr>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p>'years'</p>
                              </td>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p>year</p>
                              </td>
                           </tr>
                           <tr>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p>'months'</p>
                              </td>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p>month of year</p>
                              </td>
                           </tr>
                           <tr>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p>'days'</p>
                              </td>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p>day of month</p>
                              </td>
                           </tr>
                           <tr>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p>'hours'</p>
                              </td>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p>hour of day</p>
                              </td>
                           </tr>
                           <tr>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p>'minutes'</p>
                              </td>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p>minute of hour</p>
                              </td>
                           </tr>
                           <tr>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p>'seconds'</p>
                              </td>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p>second of minute</p>
                              </td>
                           </tr>
                           <tr>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p>'zone'</p>
                              </td>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p><a class="link" href="https://dohcs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html#timezone" target="_top">time zone</a></p>
                              </td>
                           </tr>
                        </tbody>
                     </table>
                  </div>
               </div>
            </section>
         </section>
         <section class="section" id="_examples_4">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_examples_4"></a>10.11.6.&nbsp;Examples
                     </h3>
                  </div>
               </div>
            </div><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.date.fields('2015-01-02 03:04:05 EET', 'yyyy-MM-dd HH:mm:ss zzz')</code></pre><pre class="screen highlight"><code>  {
    'weekdays': 5,
    'years': 2015,
    'seconds': 5,
    'zoneid': 'EET',
    'minutes': 4,
    'hours': 3,
    'months': 1,
    'days': 2
  }</code></pre><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.date.fields('2015/01/02_EET', 'yyyy/MM/dd_z')</code></pre><pre class="screen highlight"><code>  {
    'weekdays': 5,
    'years': 2015,
    'zoneid': 'EET',
    'months': 1,
    'days': 2
  }</code></pre></section>
         <section class="section" id="_notes_on_formats">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_notes_on_formats"></a>10.11.7.&nbsp;Notes on formats:
                     </h3>
                  </div>
               </div>
            </div>
            <div class="itemizedlist">
               <ul class="itemizedlist" style="list-style-type: disc; ">
                  <li class="listitem">the default format is <code class="literal">yyyy-MM-dd HH:mm:ss</code></li>
                  <li class="listitem">if the format pattern doesn&#8217;t specify timezone, formatter considers dates to belong to the UTC timezone</li>
                  <li class="listitem">if the timezone pattern is specified, the timezone is extracted from the date string, otherwise an error will be reported</li>
                  <li class="listitem">the <code class="literal">to/fromSeconds</code> timestamp values are in POSIX (Unix time) system, i.e. timestamps represent the number of seconds elapsed since <a class="link" href="https://en.wikipedia.org/wiki/Unix_time" target="_top">00:00:00 UTC, Thursday, 1 January 1970</a></li>
                  <li class="listitem">the full list of supported formats is described in <a class="link" href="https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html" target="_top">SimpleDateFormat JavaDoc</a></li>
               </ul>
            </div>
         </section>
         <section class="section" id="_reading_single_datetime_field_from_utc_epoch_2">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_reading_single_datetime_field_from_utc_epoch_2"></a>10.11.8.&nbsp;Reading single datetime field from UTC Epoch:
                     </h3>
                  </div>
               </div>
            </div>
            <p>Extracts the value of one field from a datetime epoch.</p><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.date.field(12345)</code></pre><p>Following fields are supported:</p>
            <div class="informaltable">
               <div class="table" id="d0e12913">
                  <table class="informaltable" border="1">
                     <colgroup>
                        <col class="col_1"></col>
                        <col class="col_2"></col>
                     </colgroup>
                     <thead>
                        <tr>
                           <th style="text-align: left; vertical-align: top; ">Result field</th>
                           <th style="text-align: left; vertical-align: top; ">Represents</th>
                        </tr>
                     </thead>
                     <tbody>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>'years'</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>year</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>'months'</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>month of year</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>'days'</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>day of month</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>'hours'</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>hour of day</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>'minutes'</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>minute of hour</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>'seconds'</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>second of minute</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>'millis'</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>milliseconds of a second</p>
                           </td>
                        </tr>
                     </tbody>
                  </table>
               </div>
            </div>
         </section>
         <section class="section" id="_examples_5">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_examples_5"></a>10.11.9.&nbsp;Examples
                     </h3>
                  </div>
               </div>
            </div><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.date.field(12345, 'days')</code></pre><pre class="screen highlight"><code>    2</code></pre></section>
      </section>
      <footer><script type="text/javascript">
          (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
          })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
          //Allow Linker
          ga('create', 'UA-1192232-34','auto', {'allowLinker': true});
          ga('send', 'pageview');
          // Load the plugin.
          ga('require', 'linker');
          // Define which domains to autoLink.
          ga('linker:autoLink', ['neo4j.org','neo4j.com','neotechnology.com','graphdatabases.com','graphconnect.com']);
        </script><script type="text/javascript">
          document.write(unescape("%3Cscript src='//munchkin.marketo.net/munchkin.js' type='text/javascript'%3E%3C/script%3E"));
        </script><script>Munchkin.init('773-GON-065');</script></footer>
   </body>
</html>